package com.fmatos.amazingwallpapers.image.database;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

@Deprecated
public class ImagesDatabaseOpenHelper extends SQLiteOpenHelper {

	
	private static final String DATABASE_NAME = "images.db";
	private static final int DATABASE_VERSION = 15;
	
	//	http://www.vogella.com/tutorials/AndroidSQLite/article.html#databasetutorial_intro
	public static final String TABLE_IMAGES = "images";
	
	public static final String COLUMN_ID = "_id";
	public static final String COLUMN_URL = "url";		 // represents url from where to obtain the photo
	public static final String COLUMN_CAPTION = "caption";		
	public static final String COLUMN_FILEPATH = "file"; // represents path in filesystem
	public static final String COLUMN_ALBUM = "album";	 // should be a foreign key to the albums database
	public static final String COLUMN_DESCRIPTION = "description";
	
	// TODO add some more columns: image metadata, pin (favorite), and state (not downloaded, downloaded, corrupt, etc)

	
	
	public static final String[] ALL_COLUMNS = {
			ImagesDatabaseOpenHelper.COLUMN_ALBUM,	
			ImagesDatabaseOpenHelper.COLUMN_ID,
			ImagesDatabaseOpenHelper.COLUMN_URL,
			ImagesDatabaseOpenHelper.COLUMN_FILEPATH,
			ImagesDatabaseOpenHelper.COLUMN_CAPTION,
			ImagesDatabaseOpenHelper.COLUMN_DESCRIPTION,
			
			};
	
	private static final String TAG = ImagesDatabaseOpenHelper.class.getSimpleName();

	// Database creation sql statement
	private static final String DATABASE_CREATE = "create table "
			+ TABLE_IMAGES + "("
			+ COLUMN_ALBUM + " text," // should also be key?
			+ COLUMN_ID  + " integer primary key autoincrement, " 
			+ COLUMN_URL + " text unique not null," //" primary key text not null,"
			+ COLUMN_FILEPATH + " text,"
			+ COLUMN_CAPTION + " text,"
			+ COLUMN_DESCRIPTION + " text"
  
			+ ");";
	
	

	public ImagesDatabaseOpenHelper(Context context) {
		super(context, DATABASE_NAME, null, DATABASE_VERSION);
	}

	@Override
	public void onCreate(SQLiteDatabase database) {
		Log.d(TAG, DATABASE_CREATE);
		database.execSQL(DATABASE_CREATE);
		
		// create index blabla album
		
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		Log.w(TAG,
				"Upgrading database from version " + oldVersion + " to "
						+ newVersion + ", which will destroy all old data");
		db.execSQL("DROP TABLE IF EXISTS " + TABLE_IMAGES);
		onCreate(db);
	}
}
